import {defineStore} from "pinia";
import https from "../utils/https";
import { message } from 'ant-design-vue';
export const useArchDetail = defineStore("archdetail",{
    state:()=>{
        return{
            detailitem:{} as any,
            commentList:[] as any,

        }
    },
    actions:{
        //获取详情页数据
        async getArchDetail(id:any){
            let res = await https.get(`/api/article/${id}`)
            console.log(res.data.data,"item")
            if(res.status==200){
                this.detailitem = {...res.data.data}
            }
        },
        //获取文章评论
        async getcomments(id:string){
            let res = await https.get("/api/comment/host/"+id);
            console.log(res,"res")
            if(res.status==200){
                this.commentList = res.data.data[0]
            }
        },
        //回复评论
        async editcomment(obj:any){
            let res = await https.post("/api/comment",obj)
            console.log(res)
            if(res.status==200){
                message.success("评论成功，等待通过")
            }
        },
        //文章点赞 
        async setarchlikes(obj:any){
        // console.log(obj)/api/article/af997ac6-f904-4b8d-b6d0-356ea2a5b220/likes
        let res = await https.post(`/api/article/${obj.id}/likes`,obj.type)
        // console.log(res,"like")
        if(res.status==200){
            this.detailitem = {...res.data.data}
        }
        }
    },
    getters:{

    }
})